package com.hualan.controller;

import com.hualan.pojo.CourseComment;
import com.hualan.pojo.PageResult;
import com.hualan.pojo.Result;
import com.hualan.service.CourseCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/courseComment")
public class CourseCommentController {

    @Autowired
    private CourseCommentService courseCommentService;

    @GetMapping
    public Result queryAllCourseComment(
            String username,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize){
        PageResult pageResult= courseCommentService.queryAllCourseComment(username, page, pageSize);
        return Result.success(pageResult);
    }

    @DeleteMapping
    public Result deleteCourseComment(@RequestParam List<Integer> ids){
        courseCommentService.deleteCourseComment(ids);
        return Result.success();
    }

    @PostMapping
    public Result savecourseComment(@RequestBody CourseComment courseComment){
        courseCommentService.saveCourseComment(courseComment);
        return Result.success();
    }

    @PutMapping
    public Result updateCourseComment(@RequestBody CourseComment courseComment){
        courseCommentService.updateCourseComment(courseComment);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getCourseCommentById(@PathVariable Integer id){
        return Result.success(courseCommentService.getCourseCommentById(id));
    }
}
